package com.example.demo.service;

import com.example.demo.domain.HbdItemDictDO;
import com.example.demo.mapper.HbdItemDictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Scope("prototype")
public class QueryItemDictOperation implements ItemDictOperation {

    @Autowired
    private HbdItemDictMapper itemDictMapper;

    @Override
    public void doExecute(HbdItemDictDO itemDictDO) {
        List<HbdItemDictDO> targetList = new ArrayList<>();

        List<HbdItemDictDO> children = itemDictMapper.listChildren(itemDictDO.getItemCode());

        for(HbdItemDictDO child:children){
            targetList.add(child);
            child.opeate(this);
        }

        itemDictDO.setChildren(targetList);

    }
}
